﻿using System.Linq.Expressions;
using System;

namespace EmbeddedLanguage.SubProcessors
{
    public class JSFunctionExtractor : ExpressionToJSProcessor
    {

        public JSFunctionExtractor(string KeyVariableName)
        {
            this.KeyVariableName = KeyVariableName;
        }

        private bool Entered;

        protected override Expression VisitLambda<T>(Expression<T> node)
        {
            if (this.Entered)
            {
                return base.VisitLambda(node);
            }
            this.Entered = true;
            var incomingNS = this.CurrentNestedString;
            //NestedString ns = null;
            
            var args = this.GetNames(node.Parameters);
            if (args.Count == 1)
            {
                //this.KeyParameterName = args[0];
                this.ParameterSubstitutionsNN[args[0]] = this.KeyVariableName;
            }
            this.Visit(node.Body);
            return node;


        }

       
    }
}
